const app = getApp();
import Api from '@/services/api.js'
export default {
  data() {
    return {
      department: {}, // 部门数据
      list: []
    }
  },
  onLoad(options) {
    this.department = JSON.parse(options.department);
    uni.setNavigationBarTitle({
      title: this.department.name
    })
  },
  onShow() {
    this.getStaffList();
  },
  methods: {
    // 获取员工列表
    async getStaffList() {
      const { code, result } = await this.$request({
        url: Api.getUsersByDepartmentId,
        data: {
          departmentId: this.department.id,
          type: this.department.name == '人力部门' ? 1 : 2
        }
      });
      if (code === 200) {
        this.list = result;
      }
    },
    handleAdd(e) {
      uni.navigateTo({
        url: `/enterpriseMgmt/editStaff/index?department=${JSON.stringify(this.department)}`
      })
    },
    // 选择弹窗确认事件
    onPickerConfirm(e) {
      const idx = this.list.findIndex(i => i.key == e.key);
      if (idx == -1) {
        this.list.push(e);
      }
      // else {
      //   this.list.slice(idx, 1, e)
      // }
    }
  }
}